<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;

class Authenticate extends Middleware
{
    public function handle($request, Closure $next, ...$guards)
    {
        if (!auth()->guard($guards[0])->check()) {
            switch ($guards[0]){
                case 'admin':
                    throw new UnauthorizedHttpException('jwt-auth', '登录已过期');
                    break;
                default:
                    return redirect(route('home.login.index'));
                    break;
            }
        }
        return $next($request);
    }
}
